package com.xuan.yrmanage.web.controller;


import com.xuan.yrmanage.common.response.CommonCode;
import com.xuan.yrmanage.common.response.ResponseResult;
import com.xuan.yrmanage.domain.Permission;
import com.xuan.yrmanage.domain.request.QueryBean;
import com.xuan.yrmanage.domain.request.QueryPageBean;
import com.xuan.yrmanage.service.PermissionService;
import com.xuan.yrmanage.web.controller_api.PermissionControllerApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * FileName: PermissionController
 * Author:   xuan zongjun
 * Date:     2020/3/16 13:49
 * Description: 权限管理
 */

@RestController
@RequestMapping("/permission")
public class PermissionController implements PermissionControllerApi {
    @Autowired
    private PermissionService permissionService;


    @Override
    @PostMapping("/findAll")
    public ResponseResult findAll(@RequestBody  QueryPageBean queryPageBean) {
        try{
            return permissionService.findAll(queryPageBean);
        }catch (Exception ex){
           return  new ResponseResult( CommonCode.FAIL);
        }
    }


    @Override
    @GetMapping("/findById")
    public ResponseResult findById(@RequestParam String id) {
        try{
            return permissionService.findById(id);
        }catch (Exception ex){
            return  new ResponseResult( CommonCode.FAIL);
        }
    }

    /**
     * 修改
     * @param permission
     * @return
     */
    @Override
    @PostMapping("/edit")
    public ResponseResult edit(@RequestBody Permission permission) {
        return permissionService.edit(permission);
    }

    /**
     * 添加
     * @param permission
     * @return
     */
    @Override
    @PostMapping("/add")
    public ResponseResult add(@RequestBody Permission permission) {
        return permissionService.add(permission);
    }
}
